Shader "Unlit/ParallaxWindow"
{
	Properties
	{
		[HideInInspector] __dirty("", Int) = 1
		_Back("Back", 2D) = "white" {}
		_BackDark("Back Dark", Float) = 0.7
		_BackDepthScale("Back Depth Scale", Range(0 , 1)) = 0
		_Mid("Mid", 2D) = "white" {}
		_MidDark("Mid Dark", Float) = 0.3
		_MidDepthScale("Mid Depth Scale", Range(0 , 1)) = 0.3
		_Front("Front", 2D) = "white" {}
		_Mask("Mask", 2D) = "white" {}
		_Specular("Specular", Range(0 , 1)) = 0
		_Smoothness("Smoothness", Range(0 , 1)) = 0
	}

		SubShader
		{
			Tags{ "RenderType" = "Opaque"  "Queue" = "Geometry+0" }
			Cull Back
			ZTest LEqual
			CGINCLUDE
			#include "UnityPBSLighting.cginc"
			#include "Lighting.cginc"
			#pragma target 2.5
			#ifdef UNITY_PASS_SHADOWCASTER
				#undef INTERNAL_DATA
				#undef WorldReflectionVector
				#undef WorldNormalVector
				#define INTERNAL_DATA half3 internalSurfaceTtoW0; half3 internalSurfaceTtoW1; half3 internalSurfaceTtoW2;
				#define WorldReflectionVector(data,normal) reflect (data.worldRefl, half3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal)))
				#define WorldNormalVector(data,normal) fixed3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal))
			#endif
			struct Input
			{
				float2 texcoord_0;
				float3 viewDir;
				INTERNAL_DATA
			};

			uniform sampler2D _Back;
			uniform fixed _BackDepthScale;
			uniform fixed _BackDark;
			uniform sampler2D _Mid;
			uniform fixed _MidDepthScale;
			uniform fixed _MidDark;
			uniform sampler2D _Mask;
			uniform sampler2D _Front;
			uniform fixed _Specular;
			uniform fixed _Smoothness;

			void vertexDataFunc(inout appdata_full v, out Input o)
			{
				UNITY_INITIALIZE_OUTPUT(Input, o);
				o.texcoord_0.xy = v.texcoord.xy * float2(1,1) + float2(0,0);
			}

			void surf(Input i , inout SurfaceOutputStandardSpecular o)
			{
				o.Normal = fixed3(0,0,1);
				float2 Offset75 = ((0.0 - 1.0) * i.viewDir.xy * _BackDepthScale) + i.texcoord_0;
				float2 OffsetBack = Offset75;
				float2 Offset76 = ((0.0 - 1.0) * i.viewDir.xy * _MidDepthScale) + i.texcoord_0;
				float2 OffsetMid = Offset76;
				fixed4 tex2DNode62 = tex2D(_Mask, i.texcoord_0);
				o.Albedo = lerp(lerp((tex2D(_Back, OffsetBack) * _BackDark) , (tex2D(_Mid, OffsetMid) * _MidDark) , tex2D(_Mask, OffsetMid).g) , tex2D(_Front, i.texcoord_0) , tex2DNode62.r).xyz;
				float temp_output_87_0 = (1.0 - tex2DNode62.r);
				fixed3 temp_cast_1 = ((temp_output_87_0 * _Specular)).xxx;
				o.Specular = temp_cast_1;
				o.Smoothness = (temp_output_87_0 * _Smoothness);
				o.Alpha = 1;
			}

			ENDCG
			CGPROGRAM
			#pragma surface surf StandardSpecular keepalpha fullforwardshadows vertex:vertexDataFunc 

			ENDCG
			Pass
			{
				Name "ShadowCaster"
				Tags{ "LightMode" = "ShadowCaster" }
				ZWrite On
				CGPROGRAM
				#pragma vertex vert
				#pragma fragment frag
				#pragma target 3.0
				#pragma multi_compile_shadowcaster
				#pragma multi_compile UNITY_PASS_SHADOWCASTER
				#pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
				# include "HLSLSupport.cginc"
				#if ( SHADER_API_D3D11 || SHADER_API_GLCORE || SHADER_API_GLES3 || SHADER_API_METAL || SHADER_API_VULKAN )
					#define CAN_SKIP_VPOS
				#endif
				#include "UnityCG.cginc"
				#include "Lighting.cginc"
				#include "UnityPBSLighting.cginc"
				sampler3D _DitherMaskLOD;
				struct v2f
				{
					V2F_SHADOW_CASTER;
					float3 worldPos : TEXCOORD6;
					float4 tSpace0 : TEXCOORD1;
					float4 tSpace1 : TEXCOORD2;
					float4 tSpace2 : TEXCOORD3;
					UNITY_VERTEX_INPUT_INSTANCE_ID
				};
				v2f vert(appdata_full v)
				{
					v2f o;
					UNITY_SETUP_INSTANCE_ID(v);
					UNITY_INITIALIZE_OUTPUT(v2f, o);
					UNITY_TRANSFER_INSTANCE_ID(v, o);
					Input customInputData;
					vertexDataFunc(v, customInputData);
					float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
					half3 worldNormal = UnityObjectToWorldNormal(v.normal);
					fixed3 worldTangent = UnityObjectToWorldDir(v.tangent.xyz);
					fixed tangentSign = v.tangent.w * unity_WorldTransformParams.w;
					fixed3 worldBinormal = cross(worldNormal, worldTangent) * tangentSign;
					o.tSpace0 = float4(worldTangent.x, worldBinormal.x, worldNormal.x, worldPos.x);
					o.tSpace1 = float4(worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y);
					o.tSpace2 = float4(worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z);
					o.worldPos = worldPos;
					TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
					return o;
				}
				fixed4 frag(v2f IN
				#if !defined( CAN_SKIP_VPOS )
				, UNITY_VPOS_TYPE vpos : VPOS
				#endif
				) : SV_Target
				{
					UNITY_SETUP_INSTANCE_ID(IN);
					Input surfIN;
					UNITY_INITIALIZE_OUTPUT(Input, surfIN);
					float3 worldPos = float3(IN.tSpace0.w, IN.tSpace1.w, IN.tSpace2.w);
					fixed3 worldViewDir = normalize(UnityWorldSpaceViewDir(worldPos));
					surfIN.viewDir = IN.tSpace0.xyz * worldViewDir.x + IN.tSpace1.xyz * worldViewDir.y + IN.tSpace2.xyz * worldViewDir.z;
					surfIN.internalSurfaceTtoW0 = IN.tSpace0.xyz;
					surfIN.internalSurfaceTtoW1 = IN.tSpace1.xyz;
					surfIN.internalSurfaceTtoW2 = IN.tSpace2.xyz;
					SurfaceOutputStandardSpecular o;
					UNITY_INITIALIZE_OUTPUT(SurfaceOutputStandardSpecular, o)
					surf(surfIN, o);
					#if defined( CAN_SKIP_VPOS )
					float2 vpos = IN.pos;
					#endif
					SHADOW_CASTER_FRAGMENT(IN)
				}
				ENDCG
			}
		}
			Fallback "Diffuse"
						CustomEditor "ASEMaterialInspector"
}
